<template>
  <el-dialog
    title="用户详情"
    :visible.sync="visible"
    width="80%"
    append-to-body
  >
    <avue-form
      ref="userInfoForm"
      v-model="form"
      :option="userInfoOption"
    ></avue-form>
  </el-dialog>
</template>
<script>
import { userInfoOption } from '@/const/crud/community-content/user';
import { getObj } from '@/api/app/customer';
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    userId: [Object, String],
  },
  data() {
    return {
      form: {},
      userInfoOption: userInfoOption(),
    };
  },
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    },
  },
  watch: {
    visible: {
      handler(val) {
        if (val) {
          this.getUserDetail();
        }
      },
    },
  },
  methods: {
    async getUserDetail() {
      const res = await getObj(this.userId);
      this.form = { ...res.data.data };
      this.form.avatar = this.form.avatar
        ? this.form.avatar
        : '/img/default-avatar.png';
    },
  },
};
</script>
